package cn.tedu.tmall.admin.content.service.impl;

import cn.tedu.tmall.admin.content.dao.persist.repository.IArticleRepository;
import cn.tedu.tmall.admin.content.dao.serch.IArticleSerchRepository;
import cn.tedu.tmall.admin.content.pojo.vo.ArticleListItemVO;
import cn.tedu.tmall.admin.content.service.IArticleService;
import cn.tedu.tmall.common.pojo.po.ArticleSerchPO;
import cn.tedu.tmall.common.pojo.vo.PageData;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class ArticleService implements IArticleService {
    @Autowired
    private IArticleRepository articleRepository;
    @Autowired
    private IArticleSerchRepository articleSerchRepository;

    @Override
    public void rebuildSearch() {
        articleSerchRepository.deleteAll();
        Integer pageNum=1;
        Integer pageSize=3;
        Integer maxPage;
        PageData<ArticleSerchPO> pageData;
        do {
            pageData = articleRepository.list(pageNum, pageSize);
            maxPage=pageData.getMaxPage();
            List<ArticleSerchPO> list = pageData.getList();
            articleSerchRepository.saveAll(list);
            pageNum++;
        }while (pageNum<=maxPage);
    }
}
